#include<bits/stdc++.h>
using namespace std;
long long a[200005],dp0[3][200005],dp1[3][200005];
void read(long long &x){
    char c;
    while(!isdigit(c=getchar()));
    x=c-'0';
    while(isdigit(c=getchar())){
        x*=10;
        x+=c-'0';
    }
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    long long t;
    read(t);
    while(t--){
        memset(dp0,0,sizeof dp0);
        memset(dp1,0,sizeof dp1);
        memset(a,0,sizeof a);
        long long n,ans=LONG_LONG_MIN;
        read(n);
        for(long long i=1;i<=n;i++){
            read(a[i]);
        }
        for(long long i=1;i<=n;i++){
            for(long long j=1;j<i-1;j++){
                long long t;

                t=dp1[(i-1)%2][j];
                if(a[i]==a[i-1])t+=a[i];
                dp1[i%2][j]=max(dp1[i%2][j],t);

                t=dp0[(i-1)%2][j];
                if(a[i]==a[j])t+=a[i];
                dp1[i%2][i-1]=max(dp1[i%2][i-1],t);

                t=dp0[(i-1)%2][j];
                if(a[i]==a[i-1])t+=a[i];
                dp0[i%2][j]=max(dp0[i%2][j],t);

                t=dp1[(i-1)%2][j];
                if(a[i]==a[j])t+=a[i];
                dp0[i%2][i-1]=max(dp0[i%2][i-1],t);
            }
        }
        for(long long i=1;i<=n;i++){
            ans=max(ans,dp0[n%2][i]);
            ans=max(ans,dp1[n%2][i]);
        }
        cout << ans << '\n';
    }
    
    return 0;
}
